import pandas as pd
import numpy as np

# 0.Feel
s = pd.Series([12, -4, 7, 9])
print(s)

# 1.index：命名标签，便于插入
age = pd.Series([35, 34, 2.9, 59, 60], 
    index=['Shuai', 'Fang', 'Evan', 'Jun', "Hongyan"])
print(age)
print(age.index)
print(age.values)

# 2.Select Elements
print(age[2])
print(age['Hongyan'])
print(age[1:3])
print(age[['Fang','Hongyan']])
print(age[['Shuai']])
print(age['Shuai'])

# 3.赋值(bound, assign)
age[0] = 80
print(age)
age['Fang'] = 18
print(age)

# 4.使用Numpy对象/Series对象，定义New Series对象
# 注意：引用
tempArr = np.array([10, 20, 30, 40, 50])
s2 = pd.Series(tempArr)
print(s2)

s3 = pd.Series(age)
print(s3)
age[2] = 3
age

# 5.Filter
age[age >35]

# 6.Math
age * 2
age / 3
np.log(age)

# 7.Series的元素数量、关系(unique, counts, isin)
color = pd.Series([7, 7, 6, 9, 8, 8, 5], 
    index=['white', 'white', 'blue', 'green', 'green', 'yello', 'red'])
color
color.unique()
color.value_counts()
color.isin([8, 9])
color[color.isin([7, 8])]

# 8.NaN
nanS = pd.Series([5,-3,np.NaN,14])
nanS
nanS.isnull()
nanS[nanS.notnull()]
nanS[nanS.isnull()]

# 9.Series as Dict
mydict = {'red':2000, 'blue':1000, 'yellow':500, 'orange':1000}
myseries = pd.Series(mydict)
myseries

colors = ['yellow', 'red', 'green', 'blue', 'orange']
newseries = pd.Series(myseries, colors)
newseries

# 10.运算（Operations)
mydict2 = {'red':400, 'black':800, 'yellow':1000}
myseries2 = pd.Series(mydict2)
print(myseries + myseries2)